package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author 喵喵喵
 * Date 2025/6/5 14:51
 */
@Api(tags="菜品分类管理")
@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageCategory(CategoryPageQueryDTO dto) {
        PageResult pageResult = categoryService.pageCategory(dto);
        return Result.success(pageResult);
    }

    @ApiOperation("新增分类")
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO dto) {
        categoryService.addCategory(dto);
        return Result.success();
    }

    @ApiOperation("启用禁用菜品分类状态")
    @PostMapping("/status/{status}")
    public Result StartORStopStatus(@PathVariable Integer status, Integer id) {
        categoryService.StartORStopStatus(status, id);
        return Result.success();
    }

    @ApiOperation("删除菜品分类")
    @DeleteMapping
    public Result deleteCategoryById(Integer id) {
        categoryService.deleteCategoryById(id);
        return Result.success();
    }

    @ApiOperation("修改菜品分类")
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO dto) {
        categoryService.updateCategory(dto);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }

}
